﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FB.Bussiness;

namespace FB.admin
{
    public partial class ChanelList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            //Read all Chanel
            ChanelBO Bo = new ChanelBO();
            rptData.DataSource = Bo.GetAllChanel();
            rptData.DataBind();
        }
        protected void btnFeed_Click(Object sender, EventArgs e)
        {
            // Navigate to feed page
            int NumberVideoFeed = 0;
            ChanelBO BO = new ChanelBO();
            List<int> ListFeed = new List<int>();
            foreach (RepeaterItem ri in rptData.Items)
            {
                CheckBox chk = (CheckBox)ri.FindControl("chkItem");
                if (chk.Checked)
                {
                    NumberVideoFeed+= BO.FeedChanel(Guid.Parse(chk.Attributes["value"])).RetValue;
                }
            }

            string msg = Utilities.Common.FormatAlertMsg("Feeded successfull " + NumberVideoFeed.ToString() + " video");
            Response.Write(msg);
            LoadData();
        }

        protected void btnAdd_Click(Object sender, EventArgs e)
        {
            Response.Redirect("ChanelModify.aspx?ID=0");
        }
        protected void btnEdit_Click(Object sender, EventArgs e)
        {
            string EditID = "-1";
            foreach (RepeaterItem ri in rptData.Items)
            {
                CheckBox chk = (CheckBox)ri.FindControl("chkItem");
                if (chk.Checked)
                {
                    EditID = chk.Attributes["value"];
                }
            }
            Response.Redirect("ChanelModify.aspx?ID=" + EditID);
        }
        protected void btnDelete_Click(Object sender, EventArgs e)
        {
            ChanelBO BO = new ChanelBO();
            foreach (RepeaterItem ri in rptData.Items)
            {
                CheckBox chk = (CheckBox)ri.FindControl("chkItem");
                if (chk.Checked)
                {
                    BO.DelChanel(Guid.Parse(chk.Attributes["value"]));
                }
            }
            LoadData();
        }
        protected void btnPublish_Click(Object sender, EventArgs e)
        {
            
        }
        protected void btnUnpublish_Click(Object sender, EventArgs e)
        {
        }

    }
}